import os

szPolicyDir = os.path.join("..", "GerikSpellsDemo", "assets", "python", "GerikSpells", "Policies")

Infos = {}

for path, dirs, files in os.walk(szPolicyDir):
    if ".svn" in dirs:
        dirs.remove(".svn")

    filenames = []
    for filename in files:
        filenames.append(os.path.join(path, filename))

    for filename in filenames:
        f = open(filename, "r")
        
        bReadingClass = False
        bReadingDef = False
        bReadingCommentDocs = False
        bFindDocStart = True
        szClass = ""
        szDef = ""
        szDoc = ""

        for line in f.readlines():
            line = line.strip()
            if line.startswith("class"):
                szClass = line.split("class")[1].strip().split("(")[0].replace(":", "")
                Infos[szClass] = {}
                Infos[szClass]["doc"] = ""
                bFindDocStart = True
                bReadingCommentDocs = False
                bReadingClass = True
                bReadingDef = False

            if line.startswith("def"):
                szDef = line.split("def")[1].strip().split(":")[0]
                Infos[szClass][szDef] = ""
                bFindDocStart = True
                bReadingDef = True
                bReadingClass = False

            if (bReadingCommentDocs and line.startswith('"""')):
                bReadingCommentDocs = False
                if bReadingClass:
                    Infos[szClass]["doc"] = szDoc
                    bReadingClass = False
                else:
                    Infos[szClass][szDef] = szDoc
                    bReadingDef = False

            if (bFindDocStart and line.startswith('"""')):
                bReadingCommentDocs = True
                bFindDocStart = False
            
            if (bReadingCommentDocs and not line.startswith('"""')):
                szDoc += "%s\n" % line

            
